package com.wyhello.tube4.dao.impl;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.wyhello.tube4.dao.LoginCheckingDAO;
import com.wyhello.tube4.pojo.User;
/**
 * 
 * @author Administrator
 *
 */
public class LoginCheckingDAOImpl implements LoginCheckingDAO {

	private SessionFactory sessionFactory;
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	/**
	 * 
	 * @param user
	 * ��֤��Ϣ
	 * @return
	 * ��¼�Ƿ�ɹ�
	 */
	public User querylogin(User user){
		Session session = sessionFactory.getCurrentSession();
		String hql = "from User u where u.userName=:uname and u.password=:pswd";
		Query query = session.createQuery(hql);
		query.setString("uname", user.getUserName());
		query.setString("pswd",user.getPassword());
		List<User> list=query.list();
		User u = null;
		if(list.size()>0){
			for (User user2 : list) {
				u=user2;
			}
		}
		return u;
	}

	/**
	 * 修改密码
	 */
	public boolean updatepw(User user) {
		Session session = sessionFactory.getCurrentSession();
		try{
			session.update(user);
		}catch(Exception e){
			return false;
		}
		return true;
	}

}
